package com.http;

import com.bone.HttpResponse;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class HttpResponseV1 extends HttpResponse {
    @Override
    public void response() throws IOException {
        String body = "hello word";

        String stringBuilder = "HTTP/1.1 200 OK\r\n" +
                "Content-Length: " + body.getBytes().length + "\r\n" +
                "Content-Type: text/plain; charset-utf-8\r\n" +
                "\r\n" +
                body + "\r\n";

        OutputStream outputStream = this.getOs();
        outputStream.write(stringBuilder.getBytes(StandardCharsets.UTF_8));
    }

    /**
     * 请求行
     * @throws IOException 异常
     */
    private void parseReponseLine() throws IOException {
        OutputStream outputStream = this.getOs();
        outputStream.write("HTTP/1.1 200 OK".getBytes("ISO8859-1"));
        outputStream.write(13);
        outputStream.write(10);
    }

    private void parseReponseHeaders() throws IOException{
        String body = "hello word";
        OutputStream outputStream = this.getOs();
        outputStream.write(("Content-Length: " + body.getBytes().length).getBytes("ISO8859-1"));
        outputStream.write(13);
        outputStream.write(10);
        outputStream.write("Content-Type: text/plain; charset-utf-8".getBytes("ISO8859-1"));
        outputStream.write(13);
        outputStream.write(10);
        outputStream.write(13);
        outputStream.write(10);
    }
}
